<?php
namespace app\xdk\model;

use traits\model\SoftDelete;
use app\mogosdk\model\Mogo;
class Plan extends Mogo
{
    use SoftDelete;
    protected $table = 'dp_xdk_plan';
    protected $autoWriteTimestamp = true;
//    protected $visible=['ccc'];
    public function Tags(){
        return $this->belongsToMany('Tags','xdk_plan_tags');
    }

    public function Sign(){
        return $this->hasMany('Sign');
    }
    public function Comments(){
        return $this->hasMany('Comments');
    }

    public function Fav(){
        return $this->belongsToMany('User','xdk_plan_fav'); // attach detach
    }
    // 获取器
    public function getIsFavAttr($user_id=MOGO_ID){
        return $this->Fav()->where('user_id',$user_id)->count();
    }
    public function getSignListAttr(){

    }

    public function getRankListAttr(){
        $this->authority();


    }

    public function checkIsFav($user_id=MOGO_ID){
        return $this->Fav()->where('user_id',$user_id)->count();
    }

    public function cancelFav($user_id=MOGO_ID){
        return $this->Fav()->detach($user_id);
    }

    public function addFav($user_id=MOGO_ID){
        return $this->Fav()->attach($user_id);
    }


    public function myPlan(){
        $this->checkToken();
        $res =  $this->select();
        return json($res);
    }

    public function add(){
        return 12323;
    }

}
